/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __HAL_INTERRUPT_H__
#define __HAL_INTERRUPT_H__

/* includes (standard library, system) ---------------------------------------*/
#include <stdint.h>
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <x_module.h>
#include <x_errno.h>
/* includes (local) ----------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/

#define ERRNO_HAL_INTC_ILLEGAL_OPERATION ERRNO_JOIN(MID_HAL, 1)
#define ERRNO_HAL_INTC_ILLEGAL_IRQN      ERRNO_JOIN(MID_HAL, 2)

/* typedefs ------------------------------------------------------------------*/

typedef void (*hal_it_handler_t)(uintptr_t);

typedef struct hal_it_methods {
    int (*enable)(unsigned int irq);
    int (*disable)(unsigned int irq);
    int (*setprio)(unsigned int irq, unsigned int prio);
    void (*handler)(void);
} hal_it_methods_t;

/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

extern void hal_it_dispatch(unsigned int irq);
extern int hal_it_connect(unsigned int irq, hal_it_handler_t handler, uintptr_t arg);
extern int hal_it_disconnect(unsigned int irq);
extern int hal_it_setprio(unsigned int irq, unsigned int prio);
extern int hal_it_enable(unsigned int irq);
extern int hal_it_disable(unsigned int irq);
extern int hal_it_register(const hal_it_methods_t *methods);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __HAL_INTERRUPT_H__ */
